
#include "read_write_mutex.h"

namespace CThread
{

/**
 * Implementation of ReadWriteMutex class using POSIX rw lock
 *
 * @version $Id:$
 */
ReadWriteMutex::ReadWriteMutex()
{
	if ( pthread_rwlock_init(&rw_lock_, NULL) != 0 )
	{
		//assert(0);
	}		
}

ReadWriteMutex::~ReadWriteMutex() 
{
	if ( pthread_rwlock_destroy(&rw_lock_) != 0 )
	{
		//assert(0);
	}
}

void ReadWriteMutex::acquireRead()
{
	pthread_rwlock_rdlock(&rw_lock_); 
}

void ReadWriteMutex::acquireWrite()
{
	pthread_rwlock_wrlock(&rw_lock_); 
}

bool ReadWriteMutex::attemptRead()
{
	return pthread_rwlock_tryrdlock(&rw_lock_); 
}

bool ReadWriteMutex::attemptWrite() 
{
	return pthread_rwlock_trywrlock(&rw_lock_); 
}

void ReadWriteMutex::release() 
{
	pthread_rwlock_unlock(&rw_lock_); 
}


};

